package com.yqg.protection.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yqg.protection.common.Result;
import com.yqg.protection.entity.RecordEquipment;
import com.yqg.protection.service.IRecordEquipmentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * RecordEquipmentController 前端控制器
 * @author 小宇
 * @since 2024-09-13
 */
@RestController
@RequestMapping("/record-equipment")
public class RecordEquipmentController {

    @Resource
    private IRecordEquipmentService recordEquipmentService;

    /**
    *  新增或者更新
    */
    @PostMapping("/edit")
    public Result save(@RequestBody RecordEquipment recordEquipment) {
        return Result.success(recordEquipmentService.saveOrUpdate(recordEquipment));
    }
    /**
    *  删除
    */
    @GetMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        return Result.success(recordEquipmentService.removeById(id));
    }
    /**
    *  查询所有
    */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<RecordEquipment> queryWrapper = new QueryWrapper<>();
       List<RecordEquipment> list=  recordEquipmentService.list(queryWrapper);
        return Result.success(list);
    }
    /**
    *  根据id查询
    */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(recordEquipmentService.getById(id));
    }
    /**
    *  分页查询
    */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                                @RequestParam Integer pageSize) {
        QueryWrapper<RecordEquipment> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return Result.success(recordEquipmentService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

}

